var fs = require('fs');
var request = require('request');
var querystringify = require('querystringify');


var options = {
    url: "https://images.dmzj.com/x/%E6%95%88%E7%8E%87%E5%8E%A8%E9%AD%94%E5%AF%BC%E5%B8%88/%E7%AC%AC%E4%B8%80%E8%AF%9D_1449126934/001.jpg"
    ,
    headers: {
        'Referer':"https://manhua.dmzj.com/xiaolvchumodaoshi/43838.shtml"
        // 'Referer': "https://manhua.dmzj.com/xiaolvchumodaoshi/43838.shtml"
    }
};
request(options).on('error', function (err) {
    console.log(err);
    console.log({ success: false, info_message: "图片请求失败" });
}).pipe(fs.createWriteStream('demo.png'));

// request({
//     url: " http://www.1kkk.com/ch9-568863/chapterfun.ashx?cid=568863&page=1&key=&language=1&gtk=6&_cid=568863&_mid=39084&_dt=2018-02-05+14%3A53%3A35&_sign=d96258c16713c8f0825405842e880d6b",
//     headers: {
//         'Referer': "http://www.1kkk.com/ch9-568863"
//     }

// },function (err, res, body){
//     console.log(body);
//     var arrys = eval(body);
//     console.log(arrys);

//     request({ url: arrys[0],
//     headers: {
//         'Referer': "http://www.1kkk.com/ch9-568863"
//     }}).on('error', function (err) {
//         console.log(err);
//         console.log({ success: false, info_message: "图片请求失败" });
//     }).pipe(fs.createWriteStream('demo.png'));
// });

/*
var q = {
    url: 'http://www.1kkk.com/ch1-557078/chapterfun.ashx',
    Referer: 'http://www.1kkk.com/ch1-557078/',
    cid: '557078',
    _cid: '557078',
    _mid: '39423',
    page: '1',
    key: '',
    language: '1',
    gtk: '6',
    _dt: '2018-02-05 17:44:58',
    _sign: 'a0ff0a9e0100340b0a91ccf8a9441467'
};

var q2 = {
    cid: '557078',
    _cid: '557078',
    _mid: '39423',
    page: '1',
    key: '',
    language: '1',
    gtk: '6',
    _dt: '2018-02-05 17:44:58',
    _sign: 'a0ff0a9e0100340b0a91ccf8a9441467'
};

// 2018-02-05 17:48:54

// 68caccdc1ecf36cfb324d5674bc634a7


console.log(q.url+"?"+(querystringify.stringify(q2))+"");

request({
    url: q.url+"?"+(querystringify.stringify(q))+"",
    // url:'http://www.1kkk.com/ch1-557078/chapterfun.ashx?cid=557078&_cid=557078&_mid=39423&page=1&key=&language=1&gtk=6&_dt=2018-02-05+17%3A44%3A58&_sign=a0ff0a9e0100340b0a91ccf8a9441467',
    // url:'http://www.1kkk.com/ch1-557078/chapterfun.ashx?cid=557078&page=1&key=&language=1&gtk=6&_cid=557078&_mid=39423&_dt=2018-02-05+17%3A44%3A58&_sign=a0ff0a9e0100340b0a91ccf8a9441467',
    headers: {
        'Referer': q.Referer
    }

}, function (err, res, body) {
    console.log(body);

});*/